﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ServiceModel.Activation;
using System.ServiceModel;
using System.Data;
using System.Configuration;
using Model;

namespace TCDCService
{
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    [ServiceBehavior(InstanceContextMode = InstanceContextMode.Single)]
    public class RESTService : iRESTService
    {

        public Model.tcdc_mst_user GetUser(string id)
        {
            Model.tcdc_mst_user u = new Model.tcdc_mst_user();
            u.strConn = ConfigurationSettings.AppSettings["ConnString"];

            DataTable dt = u.getById(id);
            u.user_id = Convert.ToInt32(id);
            u.username = dt.Rows[0]["username"].ToString();

            return u;
        }

        public Model.RegisterModel Register(Model.RegisterModel objRegister)
        {
            tcdc_mst_user objUser = new tcdc_mst_user();
            tcdc_trn_user_campaign objCampaign = new tcdc_trn_user_campaign();

            objUser.strConn = ConfigurationSettings.AppSettings["ConnString"];
            objCampaign.strConn = ConfigurationSettings.AppSettings["ConnString"];

            objUser.username = objRegister.email;
            objUser.user_type_id = 1;
            objUser.fname_th = objRegister.fname_th;
            objUser.fname_en = objRegister.fname_en;
            objUser.lname_th = objRegister.lname_th;
            objUser.lname_en = objRegister.lname_en;

            int user_id = objUser.insertData(objUser);

            objCampaign.user_id = user_id;
            objCampaign.status = "pending";

            objCampaign.insertData(objCampaign);

            return objRegister;
        }
    }
}